import { Entity, Column, PrimaryGeneratedColumn, ManyToMany, JoinTable } from "typeorm";
// import { UserRole } from "../../entities/user_role.entities";
import { Role } from "../../role/entities/role.entity";

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: string;

  @Column()
  name: string;

  @Column({
    type: "varchar",
    unique: true,
    comment: "用户名",
    name: "username"
  })
  username: string;

  @Column({ select: false })
  password: string;

  @Column({
    type: "int",
    default: 0
  })
  status: number;

  @Column({
    type: "int",
    default: 1
  })
  auth: number;

  @Column({
    type: "varchar"
  })
  phone: string;

  @ManyToMany(() => Role, role => role.users)
  @JoinTable({
    name: "user_role",
    joinColumn: { name: "user_id", referencedColumnName: "id" },
    inverseJoinColumn: { name: "role_id", referencedColumnName: "id" }
  })
  roles: Role[];

  @Column({ type: "timestamp", default: () => "null" })
  birthday: Date;

  @Column("simple-array")
  roleIds: string[];

  @Column("varchar")
  email: string;

  @Column("int")
  gender: number;

  @Column({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
  create_time: Date;

  @Column({ type: "timestamp" })
  update_time: Date;
}
